/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.upc.fulbitofacil.dao;

import edu.upc.fulbitofacil.entity.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;

/**
 *
 * @author Omar
 */
public class AlquilerCanchaDAO {

    BaseDAO base;

    public AlquilerCanchaDAO() {
    }

    public Integer insertar(Alquiler alquiler) throws FulbitoFacilException {
        String insert = "insert into ZALQCANCH(NROITEM,IDCAN,IDLOCAL,FECRESER,HHINI,HHFIN) " + "values (?,?,?,?,?,?)";

        List list = new ArrayList();

        list.add(alquiler.getNROITEM());
        list.add(alquiler.getIDCAN());
        list.add(alquiler.getIDLOCAL());
        list.add(alquiler.getFECRESER());
        list.add(alquiler.getHHINI());
        list.add(alquiler.getHHFIN());
        //list.add(alquiler.getTOTALQU());

        base = new BaseDAO();
        return base.insert(insert, list);
    }

    public Alquiler Buscar(Alquiler alquiler) throws FulbitoFacilException, SQLException {

        String Select = "select NROITEM from ZALQCANCH where nroitem = '" + alquiler.getNROITEM() + "'";
        //Select = String.format(Select, alquiler.getNROITEM());

        Alquiler alquilerRetorno = new Alquiler();

        base = new BaseDAO();

        ResultSet rs = base.select(Select);

        /*** Recorrer fila a fila el resultado ****/
        while (rs.next()) {
            alquilerRetorno.setNROITEM(rs.getString("NROITEM"));
            return alquilerRetorno;
        }
        return null;
    }
}
